<?php

class HangController extends Controller {

    /**
     * 投保
     */
    public function actionInsure() {
        $data = trim(file_get_contents("php://input"));
        if (empty($data)) {
            $this->hangInsureError("无参数");
        }
        $this->log("同程投保申请航综报文格式：".$data);
        $xml_parser = xml_parser_create();
        if(!xml_parse($xml_parser,$data,true)){
            xml_parser_free($xml_parser);
            $this->hangInsureError("参数错误");
        }
        $data = simplexml_load_string($data);
        $data = json_decode(json_encode((array) $data), true);

        $model = CsHangConfig::model()->findByAttributes(array('third_party_code'=>$data['ProductCode']));
        if (!$model) {
            $this->hangInsureError("产品不存在");
        }

        //判断成功的请求是否重复提交,
        $dist = Db2CsXcImportinfo::model()->findByAttributes(array(
            'cWaterNo'=>$data['CWaterNo']
        ));
        if($dist && $dist->retCode == "00") {
            //如果重复  则返回已投保信息
            switch ($dist->in_company) {
                case "TA":$company = 4;break;
                case "RB":$company = 5;break;
                case "TB":$company = 6;break;
            }
            $xml_content = '<?xml version="1.0" encoding="UTF-8"?>
            <ApplyResponse>
                <CWaterNo>'.$dist->cWaterNo.'</CWaterNo>
                <endDate>'.$dist->endDate.'</endDate>
                <policyNum>'.$dist->policyNum.'</policyNum>
                <retCode>'.$dist->retCode.'</retCode>
                <retDesc>'.$dist->retDesc.'</retDesc>
                <startDate>'.$dist->startDate.'</startDate>
                <policyStatus>'.$dist->policyStatus.'</policyStatus>
                <RealDate>'.$dist->realDate.'</RealDate>
                <strLockKey>'.$dist->strLockKey.'</strLockKey>
                <company>'.$company.'</company>
            </ApplyResponse>';
            echo $xml_content;die;
        } else {
            $transaction= Yii::app()->db2->beginTransaction();
            try{
                //投保人
                $holder = new Db2CsPolicyholders();
                $holder->ApplicantName = $data['ApplicantName'];
                $holder->ApplicantZJNum = $data['ApplicantZJNum'];
                $holder->ApplicantZJType = $data['ApplicantZJType'];
                $holder->ApplicantMobile = $data['ApplicantMobile']?$data['ApplicantMobile']:'';
                $holder->ApplicantType = $data['ApplicantType'];
                if($data['ApplicantBirthday']){
                    $holder->birthday = date('Y-m-d',strtotime($data['ApplicantBirthday']));
                }else{
                    $holder->birthday = $this->birthIDCard($data['ApplicantZJNum']);
                }
                if($data['ApplicantSex']){
                    $holder->sex = $data['ApplicantSex'];
                }else{
                    $holder->sex = $this->sexIDCard($data['ApplicantZJNum']);
                }
                $holder->create_time = time();
                $holder->save(false);

                //被保人列表信息
                $InsuedInfo = $data['InsuedInfoInfoList'];
                //存入出保交易流水表   后续投保使用
                $approval = new Db2CsApprovaltrans();
                $approval->TransID = $data['CWaterNo'];
                $approval->MerchantNo = 'test';
                $approval->TransDate = date('Ymd',time());
                $approval->TransTime = date('His',time());
                $approval->EffectDate = date('Ymd',strtotime($data['StartDate']));
                $approval->EffectTime = date('His',strtotime($data['StartDate']));
                $approval->proposer_id = $holder->id;
                $approval->ProductCode = $model->riskCode;
                $approval->rationType = $model->rationType;
                $approval->riskCode = $model->riskCode;
                $approval->startDate = $data['StartDate'];
                $approval->endDate = $data['EndDate'];;
                $approval->waterNo = $data['CWaterNo'];
                $approval->OrderID = $data['OrderNo'];
                $approval->issuedDate = $data['IssuedDate'];
                $approval->inputDate = $data['InputedDate'];
                $approval->holderNum = count($InsuedInfo);
                $approval->issuedDate = $data['IssuedDate'];
                $approval->InsuranceNum = $data['AviationRiskInfo']['shareNum'];
                $approval->FlightNo = $data['AviationRiskInfo']['FlightNum'];
                $approval->flightNum = $data['AviationRiskInfo']['FlightNum'];
                $approval->DepartureCity = $data['AviationRiskInfo']['DepartureCity'];
                $approval->DepartureDate = date('Ymd',strtotime($data['AviationRiskInfo']['DepartureDate']));
                $approval->DepartureTime = date('Hms',strtotime($data['AviationRiskInfo']['DepartureDate']));
                $approval->ArrivalCity = $data['AviationRiskInfo']['ArrivalCity'];
                $approval->ArrivalDate = date('Ymd',strtotime($data['AviationRiskInfo']['ArrivalDate']));
                $approval->ArrivalTime = date('Hms',strtotime($data['AviationRiskInfo']['ArrivalDate']));
                $approval->departDate = $data['AviationRiskInfo']['DepartureDate'];
                $approval->createTime = time();
                $approval->save(false);
                //被保人
                foreach ($InsuedInfo as $value) {
                    $Insued = new Db2CsInsuredinfo();
                    $Insued->approvaltrans_id = $approval->id;
                    $Insued->importpolicy_id = 0;
                    $Insued->InsuedName = $value['InsuedName'];
                    $Insued->InsuedZJNo = $value['InsuedZJNo'];
                    $Insued->InsuedZJType = $value['InsuedZJType'];
                    $Insued->InsuedMobile = $value['InsuedMobile']?$value['InsuedMobile']:'';
                    if($value['InsuedBirthday']){
                        $Insued->birthday = date('Y-m-d',strtotime($value['InsuedBirthday']));
                    }else{
                        $Insued->birthday = $this->birthIDCard($value['InsuedZJNo']);
                    }
                    if($value['InsuedSex']){
                        $Insued->sex = $value['InsuedSex'];
                    }else{
                        $Insued->sex = $this->sexIDCard($value['InsuedZJNo']);
                    }
                    $Insued->create_time = time();
                    $Insued->save(false);
                }

                //根据产品动态分配
                $thirdPartyCode = $data['ProductCode'];  //提供给第三方的产品编号
                $dist->retCode == "11"?$in_company = $dist->in_company:$in_company = null;
                $productObj = $this->getTargetCompany($thirdPartyCode,$in_company);

                $param['waterNo'] = $data['CWaterNo'];
                $param['orderNo'] = $data['OrderNo'];
                $param['startDate'] = $data['StartDate'];
                $param['endDate'] = $data['EndDate'];
                $param['departureCity'] = $data['AviationRiskInfo']['DepartureCity'];
                $param['arrivalCity'] = $data['AviationRiskInfo']['ArrivalCity'];
                $param['approvaltrans_id'] = $approval->id;

                switch ($productObj->in_company) {
                    case "TA":$this->TA($param,$productObj);break;//天安
                    case "RB":$this->RB($param,$productObj);break;//人保
                    case "TB":$this->TB($param,$productObj);break;//太保
                    default:$this->hangInsureError("保司错误");break;
                }
                $transaction->commit();
            } catch (CDbException $e) {
                $this->hangInsureError("程序内部错误",false);
                $transaction->rollback();
            }
        }
    }

    /*
     * 投保太保
     */
    public function TB($param,$productObj) {
        $url = Yii::app()->params['Taibao_hang_toubao'];
        $xml = $this->TBxml($param);
        $datas = array(
            'requestMessage'=>$xml,
            'documentProtocol'=>'CPIC_ECOM',
            'messageRouter'=>'3',
            'tradingPartner'=>'SZTC',
        );
        $header = array();
        $startime=microtime(true);
        $ret = $this->curl_https($url, $datas, $header);
        $endtime=microtime(true);
        $alltime=$endtime-$startime;
        $this->log("太保投保申请报文：".$datas);
        $this->log("太保投保返回报文：".$ret);
        $this->log("太保投保反应时间（秒）：".$alltime);
        $sk = simplexml_load_string($ret);
        $result = json_decode(json_encode($sk),TRUE);
        $this->handleInsureResult($result,$param,$productObj);
    }

    /*
     * 投保人保
     */
    public function RB($param,$productObj) {
        require_once('protected/extensions/nusoap/nusoap.php');
        $url = Yii::app()->params['Renbao_hang_toubao'];
        $client = new nusoap_client($url, 'wsdl','','','','');
        $client->soap_defencoding = 'UTF-8';
        $client->decode_utf8 = false;
        $client->xml_encoding = 'GB2312';
        $datas = $this->RBxml($param,$productObj);
        $aryPara = array('interfaceNo'=>'001009','datas'=>$datas);
        $startime=microtime(true);
        $ret = $client->call('insureService', $aryPara);
        $endtime=microtime(true);
        $alltime=$endtime-$startime;
        $this->log("人保投保申请报文：".$aryPara);
        $this->log("人保投保返回报文：".$ret);
        $this->log("人保投保反应时间（秒）：".$alltime);
        $result = json_decode($ret);
        $this->handleInsureResult($result,$param,$productObj);
    }

    /*
     * 投保天安
     */
    public function TA($param,$productObj) {
        $uri =  Yii::app()->params['Tianan_hang_toubao'];
        $req_str = $this->TAxml($param,$productObj);
        $startime=microtime(true);
        $ret = $this->request_by_curl($uri,$req_str);
        $endtime=microtime(true);
        $alltime=$endtime-$startime;
        $this->log("天安投保申请报文：".$req_str);
        $this->log("天安投保返回报文：".$ret);
        $this->log("天安投保反应时间（秒）：".$alltime);
        $result = json_decode($ret);
        $this->handleInsureResult($result,$param,$productObj);
    }

    public function TBxml($param) {
        $appData = Db2CsApprovaltrans::model()->findByPk($param['approvaltrans_id']);
        $holderData = Db2CsPolicyholders::model()->findByPk($appData->proposer_id);
        $insuedData = Db2CsInsuredinfo::model()->findByAttributes(array("approvaltrans_id"=>$appData->id));
        $deptCity = Db2InFigurethree::model()->findByAttributes(array('code'=>$param['departureCity']));
        $arrlCity = Db2InFigurethree::model()->findByAttributes(array('code'=>$param['arrivalCity']));
        $time = time();
        return '<?xml version="1.0" encoding="UTF-8"?>
                    <request>
                        <head>
                            <!--合作方编码-->
                            <partnerCode>SZTC</partnerCode>
                            <!--业务交易码-->
                            <transactionCode>108001</transactionCode>
                            <!--交易流水号-->
                            <messageId>SZTC'.date("YmdHis",time()).rand(100000,99999).'</messageId>
                            <!--交易时间-->
                            <transactionEffectiveDate>'.date("Y-m-d H:i:s",time()).'</transactionEffectiveDate>
                            <!--用户-->
                            <user>SZTC</user>
                            <!--密码-->
                            <password>+kp0LXaWRRWq2bsb/EJR22O2aqjghfCrGe/OaJJheaJttbKcDxlXiDYfpcxLK1fKm75rGAjtNsTFuxt/v/F+Vw==</password>
                        </head>
                        <body>
                            <!-- 保单提交请求 -->
                            <PolicyApplyRequest>
                                <!-- 保单基本信息 -->
                                <PolicyBaseInfo>
                                    <!-- 唯一标识 -->
                                    <uniqueFlag>'.$appData->waterNo.'</uniqueFlag>
                                    <!-- 终端号 -->
                                    <terminalNo>SZTC</terminalNo>
                                    <!-- 方案代码 -->
                                    <planCode>PN23D298001600000026</planCode>
                                    <!-- 团个单标志 S为个单 G为团单-->
                                    <groupInsuranceFlag>S</groupInsuranceFlag>
                                    <!-- 打印方式 0为电子打印 1为纸质打印 3为签发打印 -->
                                    <billType>0</billType>
                                    <!-- 承保份数 -->
                                    <coverageCopies>1</coverageCopies>
                                    <!-- 保险起期（订票时间） yyyy-MM-dd HH:mm:ss -->
                                    <startDate>'.$appData->startDate.'</startDate>
                                    <!-- 保险止期（计划到达＋24） yyyy-MM-dd HH:mm:ss -->
                                    <endDate>'.date('Y-m-d H:i:s',strtotime($appData->endDate)+86400).'</endDate>
                                    <!-- 保单总保额，可不填 -->
                                    <sumInsured/>
                                    <!-- 保单总保费，可不填 -->
                                    <policyPremium/>
                                    <!-- 支付方式 1-CHINAPAY-对公 2-CHINAPAY-对私 3-目前未使用 4-微信 -->
                                    <paymentWay>1</paymentWay>
                                    <!-- 支付地址 -->
                                    <wxUrl>#</wxUrl>
                                </PolicyBaseInfo>
                                <!-- 投保人 -->
                                <Applicant>
                                    <!-- 客户名称 -->
                                    <customerName>'.$holderData->ApplicantName.'</customerName>
                                    <!-- 证件类型 1-身份证 2-护照 3-其他 4-组织机构代码 5-营业执照 6-其他 -->
                                    <certificateType>'.intval($holderData->ApplicantZJType).'</certificateType>
                                    <!-- 证件号码 -->
                                    <certificateCode>'.$holderData->ApplicantZJNum.'</certificateCode>
                                    <!-- 客户性别 0-未说明 1-男 2-女 -->
                                    <customerGender>'.intval($holderData->sex).'</customerGender>
                                    <!-- 客户生日 yyyy-MM-dd -->
                                    <customerBirthday>'.$holderData->birthday.'</customerBirthday>
                                    <!-- 联系地址 -->
                                    <comAddress></comAddress>
                                    <!-- 移动电话 -->
                                    <mobile>'.$holderData->ApplicantMobile.'</mobile>
                                    <!-- 电子邮箱 -->
                                    <email></email>
                                </Applicant>
                                <!-- 被保险人列表 -->
                                <InsuredList>
                                    <Insured>
                                        <!-- 被保人编号 -->
                                        <insuredCode>1</insuredCode>
                                        <!-- 客户名称 -->
                                        <customerName>'.$insuedData->InsuedName.'</customerName>
                                        <!-- 证件类型 1-身份证 2-护照 3-其他 4-组织机构代码 5-营业执照 6-其他 -->
                                        <certificateType>'.intval($insuedData->InsuedZJType).'</certificateType>
                                        <!-- 证件号码 -->
                                        <certificateCode>'.$insuedData->InsuedZJNo.'</certificateCode>
                                        <!-- 客户性别 0-未说明 1-男 2-女 -->
                                        <customerGender>'.intval($insuedData->sex).'</customerGender>
                                        <!-- 客户生日 yyyy-MM-dd -->
                                        <customerBirthday>'.$insuedData->birthday.'</customerBirthday>
                                        <!-- 受益方式 1-法定（默认）2-均分 3-比例 4-顺位 0-其他 -->
                                        <benefitWay>1</benefitWay>
                                    </Insured>
                                </InsuredList>
                                <!-- 受益人列表 -->
                                <ClaimantList>
                                    <Claimant>
                                        <!-- 受益人被保人编号 -->
                                        <beneficiaryInsuredNo>1</beneficiaryInsuredNo>
                                        <!-- 客户名称 -->
                                        <customerName>'.$insuedData->InsuedName.'</customerName>
                                        <!-- 证件类型 1-身份证 2-护照 3-其他 4-组织机构代码 5-营业执照 6-其他 -->
                                        <certificateType>'.intval($insuedData->InsuedZJType).'</certificateType>
                                        <!-- 证件号码 -->
                                        <certificateCode>'.$insuedData->InsuedZJNo.'</certificateCode>
                                        <!-- 客户性别 0-未说明 1-男 2-女 -->
                                        <customerGender>'.intval($insuedData->sex).'</customerGender>
                                        <!-- 受益比例 -->
                                        <benefitRate>1</benefitRate>
                                        <!-- 受益人顺序 1-第一 2-第二 3-第三 4-第四 -->
                                        <beneficiaryOrder>1</beneficiaryOrder>
                                        <!-- 与被保险人关系 0-本人（默认） 1-配偶 2-子女 3-父母 4-其他 -->
                                        <relationshipWithTheInsured>0</relationshipWithTheInsured>
                                    </Claimant>
                                </ClaimantList>
                                <!-- 保单子险信息列表 -->
                                <CoverageList>
                                    <Coverage>
                                        <!-- 子险代码 意外伤害-->
                                        <coverageCode>23D2980000000007S0</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>600000</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>12</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 意外医疗-->
                                        <coverageCode>23D2980000000007WB</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>50000</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>3</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误1小时(含)-2小时(不含)-->
                                        <coverageCode>23U4980000000000FB</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>50</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误2小时(含)-3小时(不含)-->
                                        <coverageCode>23U4980000000000FC</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>200</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误3小时(含)-4小时(不含)-->
                                        <coverageCode>23U4980000000000FD</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>300</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误4小时(含)-5小时(不含)-->
                                        <coverageCode>23U4980000000000FE</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>400</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误5小时(含)-6小时(不含)-->
                                        <coverageCode>23U4980000000000FF</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>400</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误6小时(含)-7小时(不含)-->
                                        <coverageCode>23U4980000000000FG</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>400</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班延误7小时及以上-->
                                        <coverageCode>23U4980000000000FH</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>400</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>25</policyPremium>
                                    </Coverage>
                                    <Coverage>
                                        <!-- 子险代码 航班取消、航班返航、航班备降-->
                                        <coverageCode>23U4980000000000FI</coverageCode>
                                        <!-- 保单保额 -->
                                        <sumInsured>100</sumInsured>
                                        <!-- 保单保费 -->
                                        <policyPremium>0</policyPremium>
                                    </Coverage>
                                </CoverageList>
                                <!-- 保单因子 -->
                                <FactorList>
                                    <Factor>
                                        <!-- 因子代码 航班号-->
                                        <factorCode>B4001</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$appData->flightNum.'</factorValue>
                                    </Factor>
                                    <Factor>
                                        <!-- 因子代码 乘机日期-->
                                        <factorCode>B4002</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$appData->DepartureDate.'</factorValue>
                                    </Factor>
                                    <Factor>
                                        <!-- 因子代码 起始地点-->
                                        <factorCode>W3000</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$deptCity->name.'</factorValue>
                                    </Factor>
                                    <Factor>
                                        <!-- 因子代码 订票日期-->
                                        <factorCode>HC000</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$appData->issuedDate.'</factorValue>
                                    </Factor>
                                    <Factor>
                                        <!-- 因子代码 航班目的地-->
                                        <factorCode>HC001</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$arrlCity->name.'</factorValue>
                                    </Factor>
                                    <Factor>
                                        <!-- 因子代码 航班起飞时间-->
                                        <factorCode>HC002</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$appData->DepartureDate.'</factorValue>
                                    </Factor>
                                    <Factor>
                                        <!-- 因子代码 航班到达时间-->
                                        <factorCode>HC003</factorCode>
                                        <!-- 因子值 -->
                                        <factorValue>'.$appData->ArrivalDate.'</factorValue>
                                    </Factor>
                                </FactorList>
                                <!-- 电子保单关联信息 -->
                                <EPolicyInfo>
                                    <!-- 短信发送标志 1-发送 0-不发送 -->
                                    <messageFlag>0</messageFlag>
                                    <!-- 短信接收手机号 -->
                                    <electronPolicyMobile>'.$holderData->ApplicantMobile.'</electronPolicyMobile>
                                    <!-- 邮件发送标志 1-发送 0-不发送 -->
                                    <emailFlag>0</emailFlag>
                                    <!-- 电子保单接收邮箱 -->
                                    <electronPolicyEmail></electronPolicyEmail>
                                    <!-- 是否返回PDF字节流 -->
                                    <returnPDFFlag>0</returnPDFFlag>
                                </EPolicyInfo>
                            </PolicyApplyRequest>
                        </body>
                    </request>
        ';
    }

    public function RBxml($param) {
        $send = Db2CsApprovaltrans::model()->findByPk($param['approvaltrans_id']);
        $pro = Db2CsPolicyholders::model()->findByPk($send->proposer_id);
        $insuedData = Db2CsInsuredinfo::model()->findByAttributes(array("approvaltrans_id"=>$send->id));
        if($insuedData->sex == "01"){
            $sex = "M";
        }else{
            $sex = "F";
        }
        if($pro->sex == "01"){
            $sex1 = "M";
        }else{
            $sex1 = "F";
        }
        return '<?xml version="1.0" encoding="GB2312"?>
            <ApplyRequest>
                <TransData>
                    <TransID>'.$send->TransID.'</TransID>
                    <MerchantNo>TEST</MerchantNo>
                    <TransDate>'.$send->TransDate.'</TransDate>
                    <TransTime>'.$send->TransTime.'</TransTime>
                    <OrderID>'.$send->OrderID.'</OrderID>
                    <ProductCode>'.$send->ProductCode.'</ProductCode>
                    <EffectDate>'.$send->EffectDate.'</EffectDate>
                    <EffectTime>'.$send->EffectTime.'</EffectTime>
                    <ExpiryDate>'.$send->ExpiryDate.'</ExpiryDate>
                    <ExpiryTime>'.$send->ExpiryTime.'</ExpiryTime>
                    <OwnerName>'.$insuedData->InsuedName.'</OwnerName>
                    <CardType>'.$insuedData->InsuedZJType.'</CardType>
                    <CardNo>'.$insuedData->InsuedZJNo.'</CardNo>
                    <Sex>'.$sex.'</Sex>
                    <BirthDate>'.date('Ymd',strtotime($insuedData->birthday)).'</BirthDate>
                    <Mobile>'.$insuedData->InsuedMobile.'</Mobile>
                    <NeedSMS>F</NeedSMS>
                    <Email></Email>
                    <InsuranceNum>'.$send->InsuranceNum.'</InsuranceNum>
                    <FlightNo>'.$send->FlightNo.'</FlightNo>
                    <DepartureCity>'.$send->DepartureCity.'</DepartureCity>
                    <DepartureDate>'.$send->DepartureDate.'</DepartureDate>
                    <DepartureTime>'.$send->DepartureTime.'</DepartureTime>
                    <ArrivalCity>'.$send->ArrivalCity.'</ArrivalCity>
                    <ArrivalDate>'.$send->ArrivalDate.'</ArrivalDate>
                    <ArrivalTime>'.$send->ArrivalTime.'</ArrivalTime>
                    <ProposerName>'.$pro->ApplicantName.'</ProposerName>
                    <ProposerCardType>'.$pro->ApplicantZJType.'</ProposerCardType>
                    <ProposerCardNo>'.$pro->ApplicantZJNum.'</ProposerCardNo>
                    <ProposerMobile>'.$pro->ApplicantMobile.'</ProposerMobile>
                    <ProposerBirthDate>'.date('Ymd',strtotime($pro->birthday)).'</ProposerBirthDate>
                    <ProposerGender>'.$sex1.'</ProposerGender>  
                    <ProposerNeedSMS>F</ProposerNeedSMS>
                    <ProposerEmail></ProposerEmail>
                    <ProposerRelation>00</ProposerRelation>
                    <Beneficiarys>
                        <Beneficiary>
                            <SN>1</SN>
                            <BeneficiaryName></BeneficiaryName>
                            <BeneficiaryCardType></BeneficiaryCardType>
                            <BeneficiaryCardNo></BeneficiaryCardNo>
                            <BeneficiaryBirthDate></BeneficiaryBirthDate>
                            <BeneficiaryMobile></BeneficiaryMobile>
                            <BeneficiaryNeedSMS></BeneficiaryNeedSMS>
                            <BeneficiaryEmail></BeneficiaryEmail>
                            <BeneficiaryRelation></BeneficiaryRelation>
                            <BeneficiaryRate></BeneficiaryRate>
                        </Beneficiary>
                    </Beneficiarys>
                    <Extend1></Extend1>
                </TransData>
                <TransSignature></TransSignature>
            </ApplyRequest>';
    }

    public function TAxml($param,$productObj) {
        $appData = Db2CsApprovaltrans::model()->findByPk($param['approvaltrans_id']);
        $holderData = Db2CsPolicyholders::model()->findByPk($appData->proposer_id);
        $insuedData = Db2CsInsuredinfo::model()->findAllByAttributes(array("approvaltrans_id"=>$appData->id));
        $i=0;
        $insuredDataDtoList=array();
        foreach ($insuedData  as $value) {
            $insuredDataDtoList[$i]['insuredName']=$value->InsuedName;
            $insuredDataDtoList[$i]['identifyType']=$value->InsuedZJType;
            $insuredDataDtoList[$i]['identifyNumber']=$value->InsuedZJNo;
            $insuredDataDtoList[$i]['mobile']=$value->InsuedMobile;
            $insuredDataDtoList[$i]['birthday']=$value->birthday;
            $insuredDataDtoList[$i]['sex']=$value->sex;
            $i++;
        }
        $nonce = strtoupper(md5(uniqid(mt_rand(), true)));
        $time = time();
        $data = array(
            "requestHead" => array(
                "cooperation" => "tongcheng",//旧接口
                "nonce" => $nonce,
                "sign" => $this->getSign($nonce, $time),
                "timestamp" => $time,
                "tradeNo" => $time.rand(10000, 99999),
                "tradeDate" => date("Y-m-d H:i:s",time()),
            ),
            "rationType" => $productObj->rationType,
            "riskCode" => $productObj->riskCode,
            "startDate" => $appData->startDate,
            "endDate" => $appData->endDate,
            "inputDate" => $appData->inputDate,
            "holderNum" => $appData->holderNum,
            "waterNo" => $appData->waterNo,
            "issuedDate" => $appData->issuedDate,
            "salesCode" => $productObj->salesCode,
            "belongORGCode" => $productObj->belongORGCode,
            "businessMode" => $productObj->businessMode,
            "appDataDto" => array(
                "applicantName" => $holderData->ApplicantName,
                "identifyType" => $holderData->ApplicantZJType,
                "identifyNumber" => $holderData->ApplicantZJNum,
                "applicantType" => $holderData->ApplicantType,
                "mobile" => $holderData->ApplicantMobile,
                "sex" => $holderData->sex,
                "birthday" => $holderData->birthday,
            ),
            "insuredDataDtoList" => $insuredDataDtoList,
            "dynamicDto" => array(
                "fieldAA" => $appData->flightNum,//新格式
                "fieldAB" => $appData->departDate,//新格式
                "fieldAL" => $holderData->ApplicantName,
                "fieldAM" => $holderData->ApplicantZJType,
                "fieldAN" => $holderData->ApplicantZJNum,
                "fieldAO" => $holderData->ApplicantMobile,
            ),
        );
        $data = json_encode($data);
        return $data;
    }

    /**
     * @param $result 保司返回的数据
     * @param $param 其余参数
     * 处理跟保司承保后返回的数据
     */
    public function handleInsureResult($result,$param,$productObj) {
        $import = new Db2CsXcImportinfo();
        $import->approvaltrans_id = $param['approvaltrans_id'];
        $import->cWaterNo = $param['waterNo'];
        $return = array(
            'waterNo' => $param['waterNo'],
            'retCode' => '',
            'retDesc' => '',
            'policyNum' => '',
            'transTime' => '',
            'epolicyAddress' => '',
        );
        switch ($productObj->in_company) {
            case "TA":$return['company'] = 4;break;
            case "RB":$return['company'] = 5;break;
            case "TB":$return['company'] = 6;break;
        }
        if( $result ) {
            if ($productObj->in_company == "TB") {
                $return['retCode'] = $result['head']['responseCompleteMessageStatus']['messageStatusCode'] == "000000"?"00":"11";
                $return['policyNum'] = $result['body']['PolicyApplyResponse']['policyNo'];
                $return['retDesc'] = $return['retCode']=="00"?"承保成功":$result['head']['responseCompleteMessageStatus']['messageStatusDescriptionList']['messageStatusDescription']['messageStatusSubDescription'];
            }
            if ($productObj->in_company == "TA") {
                $return['retDesc'] = $result->returnMsg;
                $return['policyNum'] = $result->policyNo;
                $return['retCode'] = $result->retCode;
            }
            if ($productObj->in_company == "RB") {

            }

            if ($return['retCode'] == "00") {
                $return['transTime'] = strtotime($result->transTime)?$result->transTime:date('Y-m-d H:i:s');
                $return['epolicyAddress'] = $result->epolicyAddress;
                $import->policyNum = $return['policyNum'];
                $import->retCode = "00";
                $import->retDesc = $return['retDesc'];
                $import->startDate = $param['startDate'];
                $import->endDate = $param['endDate'];
                $import->policyStatus = '成功';
                $import->realDate = $return['transTime'];
                $import->strLockKey = '';
                $import->orderNo = $param['orderNo'];
                $import->epolicyAddress = $result->epolicyAddress;
                $import->in_company = $productObj->in_company;
                //新增分保记录
                $productObj->insure_number += 1;
                $productObj->save(false);
            } else {
                $import->retCode = "11";
                $import->retDesc = $return['retDesc'];
                $import->policyStatus = "失败";
                $import->realDate = time();
                $import->orderNo = $param['orderNo'];
                $import->in_company = $param['in_company'];
                $return['retCode'] = "11";
            }
        }else{
            $import->retCode = "11";
            $import->retDesc = '核心接口连接失败，请联系管理员';
            $import->policyStatus = "失败";
            $import->realDate = time();
            $import->in_company = $param['in_company'];
            $return['retCode'] = "11";
            $return['retDesc'] = '核心接口连接失败，请联系管理员';
        }
        $import->createTime = time();
        $import->save(false);
        echo $xml_content = $this->setInsureXml($return,$param);
        $this->log("同程承保返回报文：".$xml_content);
    }

    private function setInsureXml($return,$param) {
        $xml_content = '<?xml version="1.0" encoding="UTF-8"?>
            <ApplyResponse>
                <CWaterNo>'.$param["waterNo"].'</CWaterNo>
                <endDate>'.$param["endDate"].'</endDate>
                <policyNum>'.$return["policyNum"].'</policyNum>
                <retCode>'.$return["retCode"].'</retCode>
                <retDesc>'.$return["retDesc"].'</retDesc>
                <startDate>'.$param["startDate"].'</startDate>
                <policyStatus>'.($return["retCode"]=="00"?"成功":"失败").'</policyStatus>
                <RealDate>'.$return["transTime"].'</RealDate>
                <strLockKey></strLockKey>
                <company>'.$return["company"].'</company>
            </ApplyResponse>';
        return $xml_content;
    }

    function getSign($nonce,$time){
        $token = Yii::app()->params['Tianan_hang_token'];
        $data = array($token, $nonce, $time);
        sort($data, SORT_STRING);
        $sign_orign = implode('',$data);
        return $sign_haxi = sha1($sign_orign);
    }

    //日志
    private function log($content) {
        $path = "log/".date("Y-m-d");
        if (!file_exists($path)) {
            mkdir($path);
        }
        $path .= "/hang.log";
        $open=fopen($path,"a");
        fwrite($open,date('Y-m-d H:i:s').':'.$content."\r\n");
        fclose($open);
    }

    //根据产品来分保
    private function getTargetCompany($thirdPartyCode,$in_company = null) {
        if ($in_company == null) {
            $products = CsHangConfig::model()->findAllByAttributes(array("third_party_code"=>$thirdPartyCode));
            if (count($products) > 1) {
                $total_insure_number = 0;
                $proportion = array();
                foreach ($products as $product) {
                    //这个产品的所有保司的总承包数量
                    $total_insure_number += $product->insure_number;
                    $proportion[$product->in_company]['base_proportion'] = floatval($product->proportion);
                }
                foreach ($products as $product) {
                    $proportion[$product->in_company]['current_proportion'] = $product->insure_number/$total_insure_number * 100;
                    if ($proportion[$product->in_company]['current_proportion'] >= $proportion[$product->in_company]['base_proportion']) {
                        $more_half[$product->in_company] = $proportion[$product->in_company]['base_proportion'] - $proportion[$product->in_company]['current_proportion'];
                    } else {
                        $less_half[$product->in_company] = $product->proportion;
                    }
                }
                //如果less_half 有值得话,优先
                if ($less_half) {
                    $rand = array();
                    $max = 0;
                    foreach ($less_half as $key=>$value) {
                        if (intval($value) > $max) {
                            $max += intval($value);
                        }
                        for ($i=0;$i<intval($value);$i++) {
                            $rand[] = $key;
                        }
                    }
                    shuffle($rand);
                    $num = rand(0,($max-1));
                    $in_company = $rand[$num];
                } else {
                    arsort($more_half,SORT_NUMERIC);
                    $in_company = key($more_half);
                }
            }
            if (count($products) == 1) {
                $in_company = $products[0]->in_company;
            }
        }
        $product = CsHangConfig::model()->findByAttributes(array("third_party_code"=>$thirdPartyCode,'in_company'=>$in_company));
        return $product;
    }


    /*
    * 退保
    */
    public function actionSurrender() {
        // 接收投保报文
        $data = trim(file_get_contents("php://input"));
        if (empty($data)) {
            $this->hangSurrenderError("入参为空");
        }
        $this->log($data);
        $xml_parser = xml_parser_create();
        if(!xml_parse($xml_parser,$data,true)){
            xml_parser_free($xml_parser);
            $this->hangSurrenderError('入参格式错误');
        }
        $data = simplexml_load_string($data);
        $data = json_decode(json_encode((array) $data), true);
        if (empty($data['PolicyNum'])) {
            $this->hangSurrenderError("保单号不能为空");
        }
        if (empty($data['CWaterNo'])) {
            $this->hangSurrenderError("流水号不能为空");
        }
        //保单验证
        $import = Db2CsXcImportinfo::model()->findByAttributes(array('policyNum'=>$data['PolicyNum']));
        if(!$import){
            $this->hangSurrenderError("该保单号不存在");
        }

        //判断是否符合理赔
        $apps = Db2CsApprovaltrans::model()->findByPk($import->approvaltrans_id);
        $planDepartTime = date("Y-m-d H:i:s",strtotime($apps->DepartureDate.' '.$apps->DepartureTime));
        $planArriveTime = date("Y-m-d H:i:s",strtotime($apps->ArrivalDate.' '.$apps->ArrivalTime));
        $reback = Db2CsReback::model()->findByAttributes(array('flightNo'=>$apps->flightNum,'planDepartTime'=>$planDepartTime,'planArriveTime'=>$planArriveTime));

        $condition = array(
            "rationType" => $apps->rationType,
            "riskCode" => $apps->riskCode,
            "in_company" => $import->in_company
        );
        $productObj = CsHangConfig::model()->findByAttributes($condition);
        if ($reback) {
            $claimNum = 0;
            $claimMode = $productObj->claimMode;
            if ($claimMode == 0) { //老的理赔模式
                $delayTime = intval($reback->delayTime);
                $flightStatus = $reback->flightStatus;
                if($delayTime){
                    if( 60 <= $delayTime && $delayTime <= 120 ){
                        $claimNum = 50;
                    }else if( 120 < $delayTime && $delayTime <= 180 ){
                        $claimNum = 200;
                    }else if( 180 < $delayTime && $delayTime <= 240 ){
                        $claimNum = 300;
                    }else if( $delayTime > 240 ){
                        $claimNum = 400;
                    }
                }
                if( $flightStatus == "返航" || $flightStatus == "备降" || $flightStatus == "取消" ){
                    $claimNum = 100;
                }
            }
            if ($claimMode == 1) { //新的理赔模式
                if ($delayTime) {
                    if ($delayTime > 180) {
                        $claimNum = 300;
                    }
                }
                if( $flightStatus == "返航" || $flightStatus == "备降" || $flightStatus == "取消" ){
                    $claimNum = 100;
                }
            }
            if ($claimNum) {
                $this->hangSurrenderError("该保单符合理赔，无法退保");
            }
        }

        //判断是否重复提交
        $dist = Db2CsSurrendinfo::model()->findByAttributes(array(
            'PolicyNum' => $data['PolicyNum']
        ));
        if($dist && $dist->RetCode == "00"){
            switch ($dist->in_company) {
                case "TA":$company = 4;break;
                case "RB":$company = 5;break;
                case "TB":$company = 6;break;
            }
            $xml_content = '<?xml version="1.0" encoding="UTF-8"?>
            <CancelResponse>
                <CWaterNo>'.$dist->CWaterNo.'</CWaterNo>
                <policyNum>'.$dist->PolicyNum.'</policyNum>
                <RetCode>'.$dist->RetCode.'</RetCode>
                <ReturnMsg>'.$dist->ReturnMsg.'</ReturnMsg>
                <Policy_status>'.$dist->Policy_status.'</Policy_status>
                <RealDate>'.date('Y-m-d H:i:s',$dist->RealDate).'</RealDate>
                <company>'.$company.'</company>
            </CancelResponse>';
            echo $xml_content;die;
        }else{
            $transaction= Yii::app()->db2->beginTransaction();
            try {
                $surrender = New Db2CsSurrender();
                $surrender->CWaterNo = $data['CWaterNo'];
                $surrender->PolicyNum = $data['PolicyNum'];
                $surrender->ProductCode = $apps->ProductCode;
                $surrender->ProdFixedId = $apps->rationType;
                $surrender->StartDate = $data['StartDate'] ? $data['StartDate'] : null;
                $surrender->EndDate = $data['EndDate'] ? $data['EndDate'] : null;
                $surrender->Premium = $data['Premium'] ? $data['Premium'] : null;
                $surrender->CancelReason = $data['CancelReason'] ? $data['CancelReason'] : null;
                $surrender->create_time = time();
                $surrender->save(false);
                //退保

                $param['waterNo'] = $data['CWaterNo'];
                $param['policyNo'] = $data['PolicyNum'];
                $param["in_company"] = $import->in_company;
                $param['surrendpolicy_id'] = $surrender->id;
                $param['productCode'] = $apps->ProductCode;
                $param['prodFixedId'] = $apps->rationType;
                if ($import) {
                    switch ($import->in_company) {
                        case "TA":
                            $this->sTA($param);break;
                        case "RB":
                            $this->sRB($param);break;
                        case "TB":
                            $this->sTB($param);break;
                        default:
                            $this->hangSurrenderError("没找到退保保司");break;
                    }
                }
                $transaction->commit();
            }catch (CDbException $e) {
                $this->hangSurrenderError("服务器内部错误");
                $transaction->rollback();
            }
        }
    }

    //太保退保
    public function sTB($param){
        $url = Yii::app()->params['Taibao_hang_tuibao'];
        $import = Db2CsXcImportinfo::model()->findByAttributes(array('policyNum'=>$param['policyNo']));
        $app = Db2CsApprovaltrans::model()->findByPk($import->approvaltrans_id);
        $holder = Db2CsPolicyholders::model()->findByPk($app->proposer_id);
        $xml = '<?xml version="1.0" encoding="UTF-8"?>
                    <request>
                        <head>
                            <partnerCode>SZTC</partnerCode>
                            <transactionCode>108003</transactionCode>
                            <messageId>SZTC'.date("YmdHis",time()).rand(100000,99999).'</messageId>
                            <transactionEffectiveDate>'.date("Y-m-d H:i:s",time()).'</transactionEffectiveDate>
                            <user>SZTC</user>
                            <password>+kp0LXaWRRWq2bsb/EJR22O2aqjghfCrGe/OaJJheaJttbKcDxlXiDYfpcxLK1fKm75rGAjtNsTFuxt/v/F+Vw==</password>
                        </head>
                        <body>
                            <PolicyCancellationRequest>
                                <terminalNo>SZTC</terminalNo>
                                <PolicyCancellationBaseInfo>
                                    <policyNo>'.$param['policyNo'].'</policyNo>
                                    <applicationReason>退保</applicationReason>
                                    <!--单证类型-->
                                    <billType>0</billType>
                                    <contentType>1</contentType>
                                </PolicyCancellationBaseInfo>
                                <Proposer>
                                    <customerName>'.$holder->ApplicantName.'</customerName>
                                    <certificateType>'.intval($holder->ApplicantZJType).'</certificateType>
                                    <certificateCode>'.$holder->ApplicantZJNum.'</certificateCode>
                                </Proposer>
                                <EPolicyInfo>
                                    <messageFlag>1</messageFlag>
                                    <electronPolicyMobile/>
                                    <emailFlag>0</emailFlag>
                                    <electronPolicyEmail/>
                                </EPolicyInfo>
                            </PolicyCancellationRequest>
                        </body>
                    </request>
        ';
        $datas = array(
            'requestMessage'=>$xml,
            'documentProtocol'=>'CPIC_ECOM',
            'messageRouter'=>'3',
            'tradingPartner'=>'SZTC',
        );
        $header = array();
        $startime=microtime(true);
        $response = $this->curl_https($url, $datas, $header);
        $endtime=microtime(true);
        $alltime=$endtime-$startime;
        $this->log("太保退保申请报文：".trim(json_encode($datas)));
        $this->log("太保退保返回报文：".trim(json_encode($response)));
        $this->log("太保退保返回时间(秒)：".$alltime);
        $sk = simplexml_load_string($response);
        $result = json_decode(json_encode($sk),true);
        $this->handleSurrenderResult($result,$param);
    }

    //人保退保
    public function sRB($param){
        require_once('protected/extensions/nusoap/nusoap.php');
        $url = Yii::app()->params['Renbao_hang_tuibao'];
        $client = new nusoap_client($url, 'wsdl','','','','');
        $client->soap_defencoding = 'UTF-8';
        $client->decode_utf8 = false;
        $client->xml_encoding = 'GB2312';
        $xml = '<?xml version="1.0" encoding="UTF-8"?>
                    <CancelRequest>
                        <TransData>
                            <TransID>'.$param['waterNo'].'</TransID>
                            <ApprovalTransID>'.$param['waterNo'].'</ApprovalTransID>
                            <MerchantNo>TEST</MerchantNo>
                            <OriginalInsurances>
                                <OriginalInsuranceNo>'.$param['policyNo'].'</OriginalInsuranceNo>
                            </OriginalInsurances>
                            <TransDate>'.date('Ymd',time()).'</TransDate>
                            <TransTime>'.date('His',time()).'</TransTime>
                            <Extend1></Extend1>
                        </TransData>
                        <TransSignature></TransSignature>
                    </CancelRequest>';
        $aryPara = array('interfaceNo'=>'001010','datas'=>$xml);
        $startime=microtime(true);
        $response = $client->call('surrendService', $aryPara);
        $endtime=microtime(true);
        $alltime=$endtime-$startime;
        $this->log("人保退保申请报文：".$xml);
        $this->log("人保退保返回报文：".$response['return']);
        $this->log("人保退保返回时间(秒)：".$alltime);
        $rf = iconv('utf-8', 'GBK', $response['return']);
        $sk = simplexml_load_string($rf);
        $result = json_decode(json_encode($sk),true);
        $this->handleSurrenderResult($result,$param);
    }

    public function sTA($param){
        $surrender = Db2CsSurrender::model()->findByPk($param['surrendpolicy_id']);
        $nonce = strtoupper(md5(uniqid(mt_rand(), true)));
        $time=time();
        $arr = array(
            "requestHead" => array(
                "cooperation" => "tongcheng",
                "nonce" => $nonce,
                "sign" => $this->getSign($nonce, $time),
                "timestamp" => $time,
                "tradeNo" => $time.rand(10000, 99999),
                "tradeDate" => date("Y-m-d H:i:s",time()),
            ),
            'waterNo' => $param['waterNo'],
            'policyNo' => $param['policyNo'],
            'productCode' => $param['productCode'],
            'rationType' => $param['prodFixedId'],
            'cancelReason' => '退保',
        );
        $arr = json_encode($arr);
        $url =  Yii::app()->params['Tianan_hang_tuibao'];
        $startime=microtime(true);
        $response = $this->request_by_curl($url,$arr);
        $endtime=microtime(true);
        $alltime=$endtime-$startime;
        $this->log("天安退保申请报文：".$arr);
        $this->log("天安退保返回报文：".$response);
        $this->log("天安退保返回时间(秒)：".$alltime);
        $result = json_decode($response);
        $this->handleSurrenderResult($result,$param);
    }

    public function handleSurrenderResult($result,$param) {
        $return = array(
            'waterNo' => $param['waterNo'],
        );
        switch ($param['in_company']) {
            case "TA":$return['company'] = 4;break;
            case "RB":$return['company'] = 5;break;
            case "TB":$return['company'] = 6;break;
        }
        if ($result) {
            if ($param['in_company'] == "TB") {
                if (!in_array($result['body']['PolicyApplyResponse']['resultCode'],array('01','02','03','04','05'))) {
                    $return['returnMsg']='作废成功 ';
                    $return['retCode'] = '00';
                } else {
                    $return['retCode'] = '11';
                    switch ($result['body']['PolicyApplyResponse']['resultCode']) {
                        case "01":$return['returnMsg']='保单不存在';break;
                        case "02":$return['returnMsg']='保单已退保';break;
                        case "03":$return['returnMsg']='保单状态不是已生效不能做退保';break;
                        case "04":$return['returnMsg']='保单已起保不能做退保';break;
                        case "05":$return['returnMsg']='保单批改中不能做退保';break;
                        default:$return['returnMsg']='核心接口连接失败，请联系管理员';break;
                    }
                }
                $return['transTime'] = time();
                $return['policyNo'] = $param['policyNo'];
            }
            if ($param['in_company'] == "RB") {
                if ($result['TransData']['ResultStatus'] == '00') {
                    $return['retCode'] = '00';
                    $return['transTime'] = strtotime($result['TransData']['TransDate'].$result['TransData']['TransTime']);
                } else {
                    $return['retCode'] = '11';
                    $return['transTime'] = time();
                }
                $return['returnMsg'] = $result['TransData']['ResultMsg'];
                $return['policyNo'] = $param['policyNo'];
            }
            if ($param['in_company'] == "TA") {
                $return['policyNo'] = $result->policyNo;
                $return['retCode'] = $result->retCode;
                if (!isset($result->policyNo)){
                    $return['returnMsg'] = $result->retDesc;
                } else {
                    $return['returnMsg'] = $result->returnMsg;
                }
                $return['transTime'] = strtotime($result->transTime)?strtotime($result->transTime):time();
            }
            $surrenderinfo = new Db2CsSurrendinfo();
            $surrenderinfo->surrendpolicy_id = $param['surrendpolicy_id'];
            $surrenderinfo->CWaterNo = $param['waterNo'];
            $surrenderinfo->PolicyNum = $return['policyNo'];
            $surrenderinfo->RetCode = $return['retCode'];
            $surrenderinfo->ReturnMsg = $return['returnMsg'];
            $surrenderinfo->Policy_status = $return['retCode']=="00"?"成功":"失败";
            $surrenderinfo->RealDate = $return['transTime'];
            $surrenderinfo->create_time = time();
            $surrenderinfo->in_company = $param['in_company'];
            $surrenderinfo->save(false);
        } else {
            $return['retCode'] = '11';
            $return['returnMsg'] = '核心接口连接失败，请联系管理员';
            $return['policyNo'] = $param['policyNo'];
            $return['transTime'] = time();
        }
        echo $xml_content = $this->setSurrenderXml($return,$param);
        $this->log("同程退保返回报文：".$xml_content);
    }

    public function setSurrenderXml($return,$param) {
        $xml_content = '<?xml version="1.0" encoding="UTF-8"?>
        <CancelResponse>
            <CWaterNo>'.$param["waterNo"].'</CWaterNo>
            <policyNum>'.$return["policyNo"].'</policyNum>
            <RetCode>'.$return["retCode"].'</RetCode>
            <ReturnMsg>'.$return["returnMsg"].'</ReturnMsg>
            <Policy_status>'.($return["retCode"] == "00"?"成功":"失败").'</Policy_status>
            <RealDate>'.date("Y-m-d H:i:s",$return["transTime"]).'</RealDate>
            <company>'.$return["company"].'</company>
        </CancelResponse>';
        return  $xml_content;
    }

}